package com.ybt.router.tcp.sender;

import com.ybt.communicate.core.IConnection;
import com.ybt.router.core.message.IMSDMessage;
import com.ybt.router.core.sender.ISender;
import com.ybt.router.core.sender.exception.MessageSenderException;
import com.ybt.router.tcp.message.util.TCPMessageUtil;

public class TCPSender implements ISender<byte[]> {

    private IConnection conn;
    
    public void send(IMSDMessage<byte[]> msg) throws MessageSenderException {
        // TODO Auto-generated method stub
        byte[] content = null;
        try {
            content = TCPMessageUtil.message2ByteArray(msg);
            conn.send(null, content);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            throw new MessageSenderException("send message error",e);
        }
    }

    public IConnection getConnection() {
        return conn;
    }

    public void setConnection(IConnection conn) {
        this.conn = conn;
    }
    
    

}
